package org.displayextended
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	
	import org.externalassets.AssetFinder;

	 /**
	 * MovSprite
	 * 
	 * Simple Wrapper Sprite to control/initialize FLA MovieClip Assets
	 * 
	 * This class:
	 * 
	 * 1) Allows MovieClips to be controlled by a class as if it was just extended from MovieClips
	 * 2) Allows MovieClips to be loaded from external swf assets and retain all frame scripts
	 * 3) ONLY wraps MovieClip properties & methods, additional functionlity should be subclassed (see AniMovSprite)
	 * 4) Is by no means exhaustive, add wrappers for properties/methods as needed.
	 * 
	 * Usage:
	 * 
	 * 1) Initialize Class:
	 * 
	 * 	var myMovieClip:MovSprite = new MovSprite( 'path.to.some.asset' );
	 * 	addChild( myMovieClip );
	 * 
	 * 2) Call any MovieClip properties/methods with it's original frame scripts intact
	 * 	
	 * 	myMovieClip.gotoAndPlay( 'label' );
	 * 	trace( myMovieClip.totalFrames );
	 * 	etc...
	 * 
	 * @author zachary.seabrook
	*/
	public class MovSprite extends Sprite
	{
		// Trace shortcut method and toggle property
		public var showTrace:Boolean = false;
		public function t( ...rest ):void{ if( showTrace) trace( this, rest ); }
		
		private var _mc:MovieClip;
		
		/**
		 * Constructor
		 * Receives path to movieclip asset otherwise creates empty clip
		 * 
		 * @param movieClipClassPath
		 */		
		public function MovSprite( movieClipClassPath : String=null )
		{
			super();
			movieClipClassPath ? mc = AssetFinder.FindMovieClipAsset( movieClipClassPath ) : mc = new MovieClip();
			mouseChildren = true;
			addChild( mc );
		}
		
		// MovieClip Property Wrapper Getter/Setters
		
		/* 
		
		These below should not be overriden, the parent Sprite properties should be used instead
		
		override public function set x( value:Number ):void
		{
			mc.x = value;
		}
		
		override public function get x():Number
		{
			return mc.x;
		}
		
		override public function set y( value:Number ):void
		{
			mc.y = value;
		}
		
		override public function get y():Number
		{
			return mc.y;
		} */
		
		public function set enabled( value:Boolean ):void
		{
			mc.enabled = value;
		}
		
		public function get enabled():Boolean
		{
			return mc.enabled;
		}
		
		public function get currentFrame():int
		{
			return mc.currentFrame;
		}
		
		public function get currentLabel():String
		{
			return mc.currentLabel;
		}
		
		public function get totalFrames():int
		{
			return mc.totalFrames;
		}
		
		override public function set visible( value:Boolean ):void
		{
			mc.visible = value;
			super.visible = value;
		}
		
		override public function set useHandCursor( value:Boolean ):void
		{
			mc.useHandCursor = value;
		}
		
		override public function get useHandCursor():Boolean
		{
			return mc.useHandCursor;
		}
		
		override public function set buttonMode( value:Boolean ):void
		{
			mc.buttonMode = value;
		}
		
		override public function get buttonMode():Boolean
		{
			return mc.buttonMode;
		}
		
		override public function set tabEnabled( value:Boolean ):void
		{
			mc.tabEnabled = value;
		}
		
		override public function get tabEnabled():Boolean
		{
			return mc.tabEnabled;
		}
			
		// MovieClip Property Wrapper Methods
	
		override public function dispatchEvent( event:Event ):Boolean
		{
			return mc.dispatchEvent( event );
		}
	
		override public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
		{
			mc.addEventListener( type, listener, useCapture, priority, useWeakReference );
		}
	
		override public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false ):void
		{
			mc.removeEventListener( type, listener, useCapture );
		}

		public function gotoAndPlay( frame:Object, scene:String=null ):void
		{
			mc.gotoAndPlay( frame, scene );
		}
		
		public function gotoAndStop( frame:Object, scene:String=null ):void
		{
			mc.gotoAndStop( frame, scene );
		}
		
		public function stop():void
		{
			mc.stop();
		}
		
		// Class Property Getter/Setters
		
		public function set mc( value:MovieClip ):void
		{
			_mc = value;
		}
		
		public function get mc():MovieClip
		{
			if( !_mc )
				_mc = new MovieClip();
				
			return _mc;
		}
	}
}